/*
 * IC_Speed_Direction.c
 *
 *  Created on: Nov 27, 2013
 *      Author: Administrador
 */


#include "Mytypes.h"
#include "IC_Headers\IC_PwmConfig.h"
#include "IC_Headers\IC_PIT.h"
#include "IC_Headers\IC_Speed_Direction.h"


/*Counters*/
uint8 Counter;

/*Direction Value*/
uint8 Max_Temp,Max_Temp_Dir;
uint16 Foward_Value;
uint16 Direction_Value;


void vdfn_Direction_Call(){
	if(Max_Temp_Dir > 50 && Max_Temp_Dir < 100 ){
		vdfn_IC_Turn_Right (73);
	}
	else if(Max_Temp_Dir > 12 && Max_Temp_Dir < 45 ){
		vdfn_IC_Turn_Left(209);
	}
	else if(Max_Temp_Dir < 5){
		vdfn_IC_Straight();
	}
	else{
		
	}
	

}


void vdfn_Foward_Call(){
	if(Max_Temp > 50 && Max_Temp < 100 ){
		vdfn_IC_Speed_Foward(85);
	}
	else if(Max_Temp > 12 && Max_Temp < 45 ){
		vdfn_IC_Speed_Reverse(180);
	}
	else if(Max_Temp < 5){
		vdfn_IC_Speed_Stop();
	}
	else{
		
	}
	
}


void vdfn_Value_Calculate(){
	
	if(u8_Flag_Adelante_Atras == True){
		Foward_Value = 0;
		Max_Temp = u8_Adelante_Atras[0];
		for(Counter = 1; Counter < 20; Counter++){
			if(u8_Adelante_Atras[Counter] > Max_Temp){
				Max_Temp = u8_Adelante_Atras[Counter];
			}
		}
			vdfn_Foward_Call();
	}
	else if(u8_Flag_Derecha_Izquierda == True){
		Direction_Value = 0;
		Max_Temp_Dir = u8_Derecha_Izquierda[0];
		
		for(Counter = 0; Counter < 20; Counter++){
			if(u8_Derecha_Izquierda[Counter]> Max_Temp_Dir){
				Max_Temp_Dir = u8_Derecha_Izquierda[Counter];
			}
		}
		vdfn_Direction_Call();
	}
	
}


